package com.stu.wgt.test.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stu.wgt.test.bean.Payment;
import com.stu.wgt.test.mapper.PaymentMapper;
import com.stu.wgt.test.service.PaymentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wgt
 * @since 2024-02-04
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {

    @Autowired
    PaymentMapper paymentMapper;

    @Override
    public int insert(Payment payment) {
        return paymentMapper.insert(payment);
    }

    @Override
    public int delete(int id) {
        return paymentMapper.deleteById(id);
    }

    @Override
    public int update(Payment payment) {
        QueryWrapper<Payment> qw = new QueryWrapper<>();
        qw.eq("id", payment.getId());
        return paymentMapper.update(payment, qw);
    }

    @Override
    public List<Payment> selectAllPayment() {
        return paymentMapper.selectList(null);
    }

    @Override
    public List<Payment> selectById(int id) {
        QueryWrapper<Payment> qw = new QueryWrapper<>();
        qw.eq("id", id);
        return paymentMapper.selectList(qw);
    }

    @Override
    public List<Payment> selectByName(String username) {
        return null;
    }

    @Override
    public IPage<Payment> searchPayment(String query, int pageNum, int pageSize) {
        Page<Payment> page = new Page<>(pageNum, pageSize);
        QueryWrapper qw = new QueryWrapper();
        qw.like("name", query);
        IPage<Payment> paymentIPage = paymentMapper.selectPage(page, qw);
        return paymentIPage;
    }
}
